package com.ewhale.feitengguest.presenter.user.task

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.SignInDto
import com.ewhale.feitengguest.view.user.task.SignInView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2019/12/26
 * 时间：15:11
 * 包名：com.ewhale.feitengguest.presenter.user.task
 */
class SignInPresenter : IPresenter(){
    fun getSignInDetail() {
        mView.showProLoading()
        request(1, ApiHelper.USER_API.signInDetail, null)
    }

    fun sign() {
        mView.showProLoading()
        request(2, ApiHelper.USER_API.sign(), null)
    }

    override fun <T> onNext(postCode: Int, result: T?, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> (mView as SignInView).showSignDetail(result as? SignInDto)
            2 -> (mView as SignInView).sign()
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }
}
